﻿using QntPlatform.Db;
using System;
using System.Threading.Tasks;

namespace QntPlatform
{
    public interface IExchange2
    {
         
        string BuyAsync(decimal Price, decimal Amount);
        IConvertible Buy_CloseSell(decimal Price, decimal Amount);
        bool CancelOrder(IConvertible id);
        Account GetAccount();
        Order GetOrder(IConvertible id);
        Task<Record[]> GetRecordsAsync(int period, int limit = 20);
        Ticker GetTicker();
        string Sell(decimal Price, decimal Amount);
        IConvertible Sell_CloseBuy(decimal Price, decimal Amount);
    }
    public interface IExchange {
        string Name{get;}
         string Currency{get;}
        event EventHandler<Ticker> TickerChangeEvent;
          async Task<IConvertible> BuyAsync(decimal Amount, decimal Price = -1)
        {
            return await CreateOrder(Amount, SideDirection.Buy, Price);
        }
          async Task<IConvertible> SellAsync(decimal Price, decimal Amount)
        {
            return await CreateOrder(Amount, SideDirection.Sell, Price);
        }
          async Task<IConvertible> Buy_CloseSellAsync(decimal Price, decimal Amount)
        {
            return await CreateOrder(Amount, SideDirection.CloseSell, Price);
        }
          async Task<IConvertible> Sell_CloseBuyAsync(decimal Price, decimal Amount)
        {
            return await CreateOrder(Amount, SideDirection.CloseBuy, Price);
        }

        Task<bool> CancelOrderAsync(IConvertible id);
        Task<Account> GetAccountAsync();
        Order GetOrder(IConvertible id);
        Task<Record[]> GetRecordsAsync(int period, int limit = 30);
        Task<Ticker> GetTickerAsync();


          Task<string> ConnTestAsync();
       decimal getAmount(decimal amount);
        Task<IConvertible> CreateOrder(decimal amount, SideDirection sideDirection, decimal price = -1,LogInfo info=null);

        /// <summary>
        /// 期货交易中的持有仓位信息
        /// </summary>
        /// <param name="contractType">合约类型</param>
        Position[] GetPosition(string contractType);
    }
}